<template>
  <van-address-edit
    :area-list="areaList"
    show-set-default
    show-search-result
    :address-info="AddressInfo"
    :area-columns-placeholder="['请选择', '请选择', '请选择']"
    @save="OnSave"
  />
</template>

<script setup>
// 引入地区数据
import { areaList } from "@vant/area-data";
// 代理对象
const { proxy } = getCurrentInstance();
// 获取用户数据
const business = proxy.$business;
// 响应式数据
const AddressInfo = ref({
  name: business.value.nickname,
  tel: business.value.mobile,
  areaCode: business.value.district
    ? business.value.district
    : business.value.city
    ? business.value.city
    : business.value.province,
});
// 保存
const OnSave = async (values) => {
  // 组装参数
  let params = {
    busid: business.value.id,
    consignee: values.name,
    mobile: values.tel,
    code: values.areaCode,
    address: values.addressDetail,
    status: values.isDefault === true ? 1 : 0,
  };
  // 发起请求
  let result = await proxy.$http.post({
    url: "/address/add",
    params,
  });
  // 处理请求结果
  if (result.code === 1) {
    proxy.$success({
      message: result.msg,
      onClose: () => {
        proxy.$router.back();
      },
    });
  } else {
    proxy.$fail(result.msg);
  }
};
</script>